  
  var issueSaveValidationCompIds = new Array("detailsProject","detailsissueName","detailsCategory","detailsPriority",
 													  "detailsAssignedTo","detailsStatus");

 function createIssueDetails(){  
	  
var projectdetailStore=CRM.commons.createComboStore('projectdetailStore','searchIssueDashboard/detailsDropDownList','projects');
var memberDetailsStore=CRM.commons.createComboStore('memberIssueDetailsStore','searchIssueDashboard/detailsDropDownList');  
var issueCategoryStore   = CRM.commons.createComboStore('issueCategoryStoreid','searchIssueDashboard/detailsDropDownList','category');
var issueStatusStore     = CRM.commons.createComboStore('issueStatusStoreid','searchIssueDashboard/detailsDropDownList','status');
var issuePriorityStore   = CRM.commons.createComboStore('issuepriorityStoreid','searchIssueDashboard/detailsDropDownList','priority');
var issueComplexityStore = CRM.commons.createComboStore('issueComplextityStoreid','searchIssueDashboard/detailsDropDownList','complexity');
var issueResolutionStore = CRM.commons.createComboStore('issueResolutionStoreid','searchIssueDashboard/detailsDropDownList','resolution'); 
  
 var issuePanel={
		  xtype       : 'fieldset',  
		  id          : 'issuePanel',   
		  frame       : true,  
		  border      : false, 
          width       :'600', 
          height      : 350, 
		  items       :[
		                    {xtype:'hidden',id:'issueId'},
							{     
								   xtype    	: 'combo',
		                           id       	: 'detailsProject',
		                           fieldLabel   :'Projects<font color=red>*</font>',
		                           store		: projectdetailStore,
		                           value        : 'SELECT',
		                           displayField : 'name',
		                           valueField  	: 'id',
		                           triggerAction: 'all',
		                           width		: 160,
		                           editable		: false,
		                           listeners    : {select : function(combo,record,index){
						    	   bindValue('detailsProject','detailsProjectId');
						    	   memberDetailsStore.reload({
						       			params:{
						       			operation:'members',
						       			projectId:record.get('id')
						       			
						       		      }
						       		});
						         }}
		      				   },
						       {xtype:'hidden',id:'detailsProjectId',value:'0'},
							  {
		                	    xtype       : 'textfield', 
		                	    id          : 'detailsissueName',
		                	    fieldLabel  : 'Issue Name<font color=red>*</font>',
		                	    width       : '421'
		                	 },
			                {
			                	 xtype      : 'textarea',
			                	 id         : 'detailsissueReason',
			                	 fieldLabel : 'Issue Details',
			                	 align      : 'top',
			                	 width      : '421',
			                	 height     :  70
			               },
		                   {
		                	    xtype       : 'compositefield',
		                	    fieldLabel  : 'Category<font color=red>*</font>',
		                	    items       : [
			                	                   {
			                	                	   xtype         : 'combo',
			                	                	   id            : 'detailsCategory',
			                	                	   value         : 'SELECT',
			                	                	   width         : '160',
			                	                	   store         : issueCategoryStore ,
				     		   		     		   	   displayField  : 'name',
				     		   		     		   	   valueField    : 'id',
				     		   		     		   	   triggerAction : 'all',
				     		   		     		   	   typeAhead     : false,
				     		   		     		       editable	     : false,
				     		   		     		       listeners     : {select: function(){
			                	                	                         bindValue('detailsCategory','detailsCategoryId');
			                	                                         }
			                	                                      }
				     		   		     	        },
			                	                    {
					                	                xtype        :'hidden',
					                	                id           :'detailsCategoryId',
					                	                width	      : 30,
				                	                	 value        :'0'
			                	                    },
			                	                    { xtype :'displayfield', value :'Priority:<font color=red>*</font>',width:'90'},
			                	                    {
			                	                	    xtype         :'combo',
			                	                	    id            :'detailsPriority',
			                	                	    value         : 'SELECT',
			                	                	    store         : issuePriorityStore,
				     		   		     		    	displayField  : 'name',
				     		   		     		    	valueField    : 'id',
				     		   		     		    	triggerAction : 'all',
				     		   		     		    	typeAhead     : false,
				     		   		     		    	width		  : 164,
				     		   		     		        editable	  : false,
				     		   		     		        listeners     :{select:function(){
			                	                	                        bindValue('detailsPriority','detailsPriorityId');
			                	                                         }
			                 	                                        }
				     		   		     		        
				     		   		                 },
				     		   		                 {
					     		   		     		    xtype         : 'hidden',
					     		   		     		    id            :'detailsPriorityId',
					     		   		     		    value         :'0'
					     		   		     		 },
		                	                   ]
		                      },
		                      {
			            	       xtype        : 'compositefield',
			            	       fieldLabel   : 'ModuleId',
			            	       items        : [
													 {
															 xtype        : 'textfield',
															 id           : 'detailsModule', 
															 width        :'156.5'
													  },
			            	                          { xtype :'displayfield', value:'Complexity:', width:'90'},
			            	                          {
			            	                        	   xtype          : 'combo',
			            	                        	   id             : 'detailsComplexity',
			            	                        	   value          : 'SELECT',
			            	                        	   store          : issueComplexityStore,
					     		   		     		   	   displayField   : 'name',
					     		   		     		   	   valueField     : 'id',
					     		   		     		   	   triggerAction  : 'all',
					     		   		     		   	   typeAhead      : false,
					     		   		     		   	   width		  : 164,
					     		   		     		       editable	      : false,
					     		   		     		       listeners      : {select:function(){
	   	                    	                                              bindValue('detailsComplexity','detailsComplexityId');
	   	                                                                                      }
	   	                                                                      }
					     		   		     		   },
			            	                           {
			            	                        	   xtype          :'hidden',
			            	                        	   id             :'detailsComplexityId',
			            	                        	   value          :'0'
			            	                           }
			            	                        ]
			                      },
		                         {
	                        	    xtype         : 'combo',
	                        	    id            : 'detailsAssignedTo',
	                        	    fieldLabel   : 'AssignedTo<font color=red>*</font>',
	                        	    value         : 'SELECT',
	                        	    width         : '170',
	                        	    store         : memberDetailsStore,
		   		     		    	displayField  : 'name',
		   		     		    	valueField    : 'id',
		   		     		    	triggerAction : 'all',
		   		     		    	typeAhead     : false,
		   		     		        editable	  : false,
		   		     		        mode          : 'local',
		   		     		        listeners     : {select:function(){
	                    	                          bindValue('detailsAssignedTo','detailsAssignedToId');
	                                                                 }
	                                                  }
		   		     		  },
	                          {
  	                    	    xtype         : 'hidden',
  	                    	    id            : 'detailsAssignedToId', 
  	                    	    value         :'0'
  	                         },
			                  {
			                	  xtype      :'compositefield',
			                	  fieldLabel : 'Status<font color=red>*</font>',
			                	  items      : [
			                	                  {
			                	                	    xtype         : 'combo',
			                	                	    id            : 'detailsStatus',
			                	                	    value         : 'SELECT',
			                	                	    width         : '170',
			                	                	    store         : issueStatusStore,
				     		   		     		   	 	displayField  : 'name',
				     		   		     		   	 	valueField    : 'id',
				     		   		     		   	 	triggerAction : 'all',
				     		   		     		   	 	typeAhead     : false,
				     		   		     		        editable	  : false,
				     		   		     		        listeners     :{select:function(){
			                	                	                             bindValue('detailsStatus','detailsStatusId');
			                	                                                     }
			                	                                        }
				     		   		     		    },
				     		   		     		    {
				                	                	 xtype        :'hidden',
				                	                	 id           :'detailsStatusId',
				                	                	 width	      : 30,
				                	                	 value        :'0'
				                	                },
				                	                {xtype: 'displayfield', value: 'Target Date: ', width:'90'},
				                	                {
									     		    	xtype		  : 'datefield',
									     		   	 	id			  : 'detailsTargetDate',
									     		   	 	width		  : 165,
									     		   	 	format		  : 'Y-m-d',
									     		   	    value		  : '0'
									     		     },
				                	                
				     		   		     		    
				     		   		             ]
			                 },
			                 {
		                	  xtype      :'compositefield',
		                	  fieldLabel : 'Resolution',
		                	  items      : [
		                	                  {
		                                               xtype         : 'combo',
						                        	   fieldLabel    : 'Resolution',
						                        	   id            : 'detailsResolution',
						                        	   value         : 'SELECT',
						                        	   store         : issueResolutionStore,
							   		     		   	   displayField  : 'name',
							   		     		   	   valueField    : 'id',
							   		     		   	   triggerAction : 'all',
							   		     		   	   typeAhead     : false,
							   		     		   	   width		 : 165, 
							   		     		        editable	 : false,
							   		     		       listeners     :{select:function(){
					       	                                           bindValue('detailsResolution','detailsResolutionId');
					                                                  }
					                                              }
							   		     		  },
						                          {
						                        	  xtype :'hidden',
						                        	  id    :'detailsResolutionId',
						                        	  value :'0'
						                          },
						                          {xtype: 'displayfield', value: 'Date Resolved: ', width:'90'},
								     		      {
								     		    	xtype		  : 'datefield',
								     		    	id			  : 'detailsResolvedDate',
								     		   	 	width		  : 165,
								     		   	 	format		  : 'Y-m-d',
								     		    	value		  : '0'
								     		     }
			                                  ]
			                 }]
		        };
 
 var issueRootPanel =new Ext.FormPanel({
         
         id          : 'issueRootPanel',
         width       : 700,
         height      : 350,
         frame       : true,
         title       :'Create Issue ', 
         iconCls     : 'Issue',
         items       : [
                         {
                             xtype   : 'panel',
                             layout  : 'hbox',
                             items   : [issuePanel]
                         }
                       ],
         bbar        : {
                         xtype       : 'toolbar',
                         buttonAlign : 'right',
                         items       : [
                                         
 	                                       {
	   	                                    	xtype   :'button',
	   	                                    	text    :'Save',
	   	                                    	id      :'saveButton',
	   	                                    	handler:function(){
 	                                    	       			validateAndSaveIssue(this.getText());
 	                                                }
    	                                    },'-',
    	                                    {
    	     						    	    xtype   :'button',
    	     						    	    text    :'Clear',
    	     						    	    id      :'cancelButton',
    	     						    	   handler:function(){
    	                                    	issueRootPanel.getForm().reset(); 
    	     								}
    	     							}
	                                 ]
                        }
            });
            validateFormOnLoad(issueRootPanel, issueSaveValidationCompIds );
            return issueRootPanel;
       };
       
       function validateAndSaveIssue(action)
  	  {
       var form = Ext.getCmp('issueRootPanel');
       var validationSuccess = simpleFormValidation(form, issueSaveValidationCompIds);
       if(validationSuccess == 'true'){
      	 issueActions(form,'searchIssueDashboard/saveIssue','Issue Created Succefully',true); 
       }
  	 };
       
      function createIssueDetailsUpdate(){ 
    	  var projectdetailStore=CRM.commons.createComboStore('projectdetailStore','searchIssueDashboard/detailsDropDownList','projects');
    	  var memberDetailsStore=CRM.commons.createComboStore('memberIssueDetailsStore','searchIssueDashboard/detailsDropDownList'); 
    	  var issueCategoryStore   = CRM.commons.createComboStore('issueCategoryStoreid','searchIssueDashboard/detailsDropDownList','category');
    	  var issueStatusStore     = CRM.commons.createComboStore('issueStatusStoreid','searchIssueDashboard/detailsDropDownList','status');
    	  var issuePriorityStore   = CRM.commons.createComboStore('issuepriorityStoreid','searchIssueDashboard/detailsDropDownList','priority');
    	  var issueComplexityStore = CRM.commons.createComboStore('issueComplextityStoreid','searchIssueDashboard/detailsDropDownList','complexity');
    	  var issueResolutionStore = CRM.commons.createComboStore('issueResolutionStoreid','searchIssueDashboard/detailsDropDownList','resolution'); 
    	  
    	  var issuePanel={
    	 		  xtype       : 'fieldset',  
    	 		  id          : 'issuePanelUpdate', 
    	 		  frame       : true,
    	 		  border      : false, 
    	           width       :'600', 
    	           height      : 350, 
    	 		  items       :[
                                    {xtype:'hidden',id:'issueId'},
    	 							{      xtype    	: 'combo',
    	 		                           id       	: 'issueProjectName',
    	 		                           fieldLabel   :'Projects',
    	 		                           store		: projectdetailStore,
    	 		                           value        :'SELECT',
    	 		                           displayField : 'name',
    	 		                           valueField  	: 'id',
    	 		                            triggerAction: 'all',
    	 		                           width		: 160,
    	 		                           editable		: false,
    	 		                           listeners : {select : function(combo,record,index){
    	 						    	   bindValue('issueProjectName','issueProjectId');
    	 						    	   memberDetailsStore.reload({
    							       			params:{
    							       			operation:'members',
    							       			projectId:record.get('id')
    							       			
    							       		}
    							       		});
    	 						    	 
    	 						       }}
    	 		      				   } 
    	 						       ,
    	 						       {xtype:'hidden',id:'issueProjectId',value:'0'}
    	 						       ,
    	 							 {
    	 		                	    xtype       : 'textfield', 
    	 		                	    id          : 'issueName',
    	 		                	    fieldLabel  : 'Issue Name',
    	 		                	    width       : '421'
    	 		                	},
    	 			                {
    	 			                	 xtype      : 'textarea',
    	 			                	 id         : 'issueReason',
    	 			                	 fieldLabel : 'Issue Details',
    	 			                	 align      : 'top',
    	 			                	 width      : '421',
    	 			                	 height     :  70
    	 			               },
    	 		                   {
    	 		                	    xtype       : 'compositefield',
    	 		                	    fieldLabel  : 'Category',
    	 		                	    items       : [
    	 			                	                   {
    	 			                	                	   xtype         : 'combo',
    	 			                	                	   id            : 'issueCategory',
    	 			                	                	   value         : 'SELECT',
    	 			                	                	   width         : '170',
    	 			                	                	   store         : issueCategoryStore ,
    	 				     		   		     		   	   displayField  : 'name',
    	 				     		   		     		   	   valueField    : 'id',
    	 				     		   		     		   	   triggerAction : 'all',
    	 				     		   		     		   	   typeAhead     : false,
    	 				     		   		     		       editable	     : false,
    	 				     		   		     		       listeners     : {select: function(){
    	 			                	                	                         bindValue('issueCategory','issueCategoryId');
    	 			                	                                         }
    	 			                	                                      }
    	 				     		   		     	        },
    	 			                	                    {
    	 					                	                xtype        :'hidden',
    	 					                	                id           :'issueCategoryId'
    	 			                	                    },
    	 			                	                   { xtype :'displayfield', value :'Priority:',width:'90'},
	   	 			                	                    {
	   	 			                	                	    xtype         :'combo',
	   	 			                	                	    id            :'issuePriority',
	   	 			                	                	    value         : 'SELECT',
	   	 			                	                	    store         : issuePriorityStore,
	   	 				     		   		     		    	displayField  : 'name',
	   	 				     		   		     		    	valueField    : 'id',
	   	 				     		   		     		    	triggerAction : 'all',
	   	 				     		   		     		    	typeAhead     : false,
	   	 				     		   		     		    	width		  : 164,
	   	 				     		   		     		        editable	  : false,
	   	 				     		   		     		        listeners     :{select:function(){
	   	 			                	                	                        bindValue('issuePriority','issuePriorityId');
	   	 			                	                                         }
	   	 			                	                                        }
	   	 				     		   		     		        
	   	 				     		   		                 },
	   	 				     		   		                 {
	   	 					     		   		     		    xtype         : 'hidden',
	   	 					     		   		     		    id            :'issuePriorityId',
	   	 					     		   		     		    value         :'0'
	   	 					     		   		     		 },
    	 		                	                   ]
    	 		                      },
    	 			                  {
    	 			                	  xtype      :'compositefield',
    	 			                	  fieldLabel : 'ModuleId',
    	 			                	  items      : [
														  {
															 	xtype        : 'textfield',
															 	id           : 'issueModule',
															 	width        :'156.5'
														   },
    	 			                	                   { xtype :'displayfield', value:'Complexity:', width:'90'},
     	 		            	                           {
     	 		            	                        	   xtype          : 'combo',
     	 		            	                        	   id             : 'issueComplexity',
     	 		            	                        	   value          : 'SELECT',
     	 		            	                        	   store          : issueComplexityStore,
     	 				     		   		     		   	   displayField   : 'name',
     	 				     		   		     		   	   valueField     : 'id',
     	 				     		   		     		   	   triggerAction  : 'all',
     	 				     		   		     		   	   typeAhead      : false,
     	 				     		   		     		   	   width		  : 164,
     	 				     		   		     		       editable	      : false,
     	 				     		   		     		       listeners      : {select:function(){
     	    	                    	                                              bindValue('issueComplexity','issueComplexityId');
     	    	                                                                                      }
     	    	                                                                      }
     	 				     		   		     		   },
     	 		            	                           {
     	 		            	                        	   xtype          :'hidden',
     	 		            	                        	   id             :'issueComplexityId',
     	 		            	                        	   value          :'0'
     	 		            	                           }
    	 				     		   		     		    
    	 				     		   		             ]
    	 			                 },
    	 		                     {
        	                        	    xtype         : 'combo',
        	                        	    id            : 'issueAssignedTo',
        	                        	    fieldLabel   : 'AssignedTo',
        	                        	    value         : 'SELECT',
        	                        	    width         : '170',
        	                        	    store         : memberDetailsStore,
	     		   		     		    	displayField  : 'name',
	     		   		     		    	valueField    : 'id',
	     		   		     		    	triggerAction : 'all',
	     		   		     		    	typeAhead     : false,
	     		   		     		        editable	  : false,
	     		   		     		        mode          : 'local',
	     		   		     		        listeners     : {select:function(){
        	                    	                          bindValue('issueAssignedTo','issueAssignedToId');
        	                                                                 }
        	                                                  }
	     		   		     		  },
        	                          {
            	                    	    xtype         : 'hidden',
            	                    	    id            : 'issueAssignedToId', 
            	                    	    value         :'0'
            	                      },
    	 		            	      {
    	 			                	  xtype      :'compositefield',
    	 			                	  fieldLabel : 'Status',
    	 			                	  items      : [                  
					    	 		                       {
					               	                	    xtype         : 'combo',
					               	                	    id            : 'issueStatus',
					               	                	    value         : 'SELECT',
					               	                	    width         : '170',
					               	                	    store         : issueStatusStore,
						     		   		     		   	displayField  : 'name',
						     		   		     		   	valueField    : 'id',
						     		   		     		   	triggerAction : 'all',
						     		   		     		   	typeAhead     : false,
						     		   		     		    editable	  : false,
						     		   		     		    listeners     :{select:function(){
					               	                	                             bindValue('issueStatus','issueStatusId');
					               	                                                     }
					               	                                        }
						     		   		     		    },
						     		   		     		    {
						                	                	 xtype        :'hidden',
						                	                	 id           :'issueStatusId',
						                	                	 width	      : 30,
						                	                	 value        :'0'
						                	                },
						                	                {xtype: 'displayfield', value: 'Target Date: ', width:'90'},
						                	                {
    	 									     		    	xtype		  : 'datefield',
    	 									     		   	 	id			  : 'targetDate',
    	 									     		   	 	width		  : 165,
    	 									     		   	 	format		  : 'Y-m-d',
    	 									     		   	    value		  : '0'
    	 									     		     },
	                	                              ]
    	 		            	      },
    	 		            	      {
   	 								   xtype		: 'compositefield',
   	 								   fieldLabel	: 'Resolution',
   	 								   items		: [
					    	 		                      {
					    	 	                        	   xtype         : 'combo',
					    	 	                        	   fieldLabel    : 'Resolution',
					    	 	                        	   id            : 'issueResolution',
					    	 	                        	   value         : 'SELECT',
					    	 	                        	   store         : issueResolutionStore,
					    	 		   		     		   	   displayField  : 'name',
					    	 		   		     		   	   valueField    : 'id',
					    	 		   		     		   	   triggerAction : 'all',
					    	 		   		     		   	   typeAhead     : false,
					    	 		   		     		   	   width		 : 165, 
					    	 		   		     		        editable	 : false,
					    	 		   		     		       listeners     :{select:function(){
					    	        	                                           bindValue('issueResolution','issueResolutionId');
					    	                                                   }
					    	                                               }
					    	 		   		     		        
					    	 	                          },
					    	 	                          {
					    	 	                        	  xtype :'hidden',
					    	 	                        	  id    :'issueResolutionId',
					    	 	                        	  value :'0'
					    	 	                          },
    	 			                                      {xtype: 'displayfield', value: 'Date Resolved: ', width:'90'},
    	 									     		  {
    	 									     		    	xtype		  : 'datefield',
    	 									     		    	id			  : 'dateResolved', 
    	 									     		   	 	width		  : 165,
    	 									     		   	 	format		  : 'Y-m-d',
    	 									     		    	value		  : '0'
    	 									     		    }
    	 									     	]
    	 			                   }
    	 			                   
    	 			                ]
    	 		        };
    	  
    	  var issueUpdateRootPanel =new Ext.form.FormPanel({
    	          
    	          id          : 'issueRootPanel',
    	          width       : 700,
    	          height      : 350,
    	          title       :'Update Issue ',
    	          iconCls     : 'Issue',
    	          frame       : true,
    	          items       : [
    	                          {
    	                              xtype   : 'panel',
    	                              layout  : 'hbox',
    	                              items   : [issuePanel]
    	                          }
    	                        ]
    	             });
    	             return issueUpdateRootPanel; 
    	        };
    	        
   var formids=['issueProjectName','issueName','issueReason','issuePriority','issueModule','issueCategory','issueStatus','issueAssignedTo','issueComplexity','issueResolution','targetDate','dateResolved'];     
    	          
   var win;	
   function issuePopupWindow(rowdata,dupdate,dremove)
   {
	   var issueFormPanel=createIssueDetailsUpdate(); 
	  
	   win = new Ext.Window({
			title		: 'Issue Update',
			id			: 'issuePopupWindowid',
			width		: 800,
			border		: true,
			plain		: false,
			closable	: true,
			collapsible : false,
			animCollapse: false,
			draggable 	: true,
			maximizable : false,
			onEsc		: true,
			model		: true,
			items		: [
                             issueFormPanel 
			     		  ],
			bbar        : {
			                    xtype       : 'toolbar',
			                    buttonAlign : 'right',
			                    items       : [
			                        {
			                            xtype   : 'button',
			                            text    : 'Update',
			                            hidden	:dupdate,
			                            handler : function(){
			                        	issueActions(issueFormPanel,'searchIssueDashboard/updateIssue','Issue Update Sucessfully',false);
			                        }
			                        },'-',
			                        {
			                            xtype   : 'button',
			                            text    : 'Remove',
			                            hidden	:dremove,
			                            handler : function(){
			                        	  
			                               }
			                        },'-',
									{
								    	   xtype:'button',
								    	   text:'Cancel',
								    	   id:'cancelid',
								    	   
								    	   handler:function(){
											win.close();
									}
									}
			                    ]
			                }     		  
		
	});
	   issueFormPanel.getForm().loadRecord(rowdata);
	   if(dupdate)doFormReadOnly(issueFormPanel,formids,true);
	   win.show(this);
	   //disableIssueProjectUpdate(); 
	   return win;
   }
  
   function makeFormReadOnly(issueFormPanel,formids)
   {
	 
    for(var i=0;i<formids.length;i++){
     if(issueFormPanel.getForm().findField(formids[i])!=null)
    	 issueFormPanel.getForm().findField(formids[i]).setReadOnly(true);
    }  }   
       
     
   
  
    function issueActions(formPanel,url,msg,flag)
    {
    	 var pass=formPanel.getForm().findField('issueId').value;
    	 if(flag==true){pass=undefined;}
    	 if(formPanel.getForm().findField('issueId').value==pass){
    	 var values = formPanel.getForm().getValues();
    	 var encoded = Ext.encode(values);
		 Ext.Ajax.request({ 
			   url		: url,
    		   method	: 'POST', 
  	           success  : function(request) {   
			                      
	  	        		          var issueHomeGrid=Ext.getCmp('issueHomeGrid'); 
			                      var  IssueMine = Ext.getCmp('myIssueGrid');
			                      issueHomeGrid.store.reload();
			                      IssueMine.store.reload(); 
			                      formPanel.getForm().findField('issueId').value=request.responseText;  
	  	        		          alert(msg); 
		  	        		          
			},
	  	   failure: function() { alert ("Failure");}, 
	  	   jsonData: encoded  
	  	});
	}
	else{
		alert("Record is AllReady Exist.");
	}
 	}

    function disableIssueProjectUpdate(){
    	Ext.getCmp('issueProjectName').disable();
	};		
    
    	